package game.metalmax.packet.character {

	import flash.utils.ByteArray;
	
	import game.metalmax.packet.IPacket;
	import game.metalmax.packet.world.PPoint;

//角色实体
public class PHero implements IPacket{

	public var id:String;
	//名字
	public var name:String;
	//角色类型
	public var type:String;
	//Avatar
	public var avatar:PAvatar = null;
	//座驾Avatar
	public var vehicle:PVehicle = null;
	// 坐标
	public var position:PPoint = null;

	public function write(out:ByteArray):void{
		var len:int = 0;
		var i:int = 0;
		out.writeUTF(id==null?"":id);
		out.writeUTF(name==null?"":name);
		out.writeUTF(type==null?"":type);
		out.writeByte(avatar==null?0:1);
		if(avatar!=null) avatar.write(out);
		out.writeByte(vehicle==null?0:1);
		if(vehicle!=null) vehicle.write(out);
		out.writeByte(position==null?0:1);
		if(position!=null) position.write(out);
	}
	public function read(inn:ByteArray):void{
		var len:int = 0;
		var i:int = 0;
		id = inn.readUTF();
		name = inn.readUTF();
		type = inn.readUTF();
				if(inn.readByte() == 1){
avatar= new PAvatar();
avatar.read(inn);
		}
				if(inn.readByte() == 1){
vehicle= new PVehicle();
vehicle.read(inn);
		}
				if(inn.readByte() == 1){
position= new PPoint();
position.read(inn);
		}
}
}
}